from selenium import webdriver
from time import sleep
import time

class study:
    def __init__(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
        chrome_options.add_argument("disable-cache")
        chrome_options.add_argument('disable-infobars')
        chrome_options.add_argument('log-level=3')
        chrome_options.add_argument('--start-maximized')
        self.__driver = webdriver.Chrome(chrome_options=chrome_options)
        self.__handle_list = []

    @property
    def driver(self):
        return self.__driver
    
    def getElement(self, xpath):
        try:
            element = self.driver.find_element_by_xpath(xpath)
        except:
            return None
        if element.is_displayed():
            return element
        return None

    def getElements(self, xpath):
        try:
            elements = self.driver.find_elements_by_xpath(xpath)
        except:
            return None
        for element in elements:
            if not element.is_displayed():
                elements.remove(element)
        return elements

    def clickElement(self, xpath):
        try:
            self.getElement(xpath).click()
        except:
            return False
        return True

    def inputText(self, xpath, text):
        try:
            self.getElement(xpath).send_keys(text)
        except:
            return False
        return True

    def getFakeElementAfterDisplay(self, css_sellect):
        str = "return window.getComputedStyle(document.querySelector('%s'), ':after').display" % (css_sellect)
        try:
            result = self.driver.execute_script(str)
        except:
            return False
        if  result == 'none':
            return False
        else:
            return True
            
    @property
    def time(self):
        return time.strftime('%m-%d %H:%M',time.localtime(time.time())) 

